<!DOCTYPE html>
<html>
<head>
    <include file="Public:header" />
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>
<style>
	.pay-stoke-box{ position:relative;}
	.pay-stoke-btn{ position:absolute; right:15px; top:0; border-radius:0;}
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
    	<input id="id" class="hide" value="<{$user_id}>"/>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="row">
                    		<div class="form-group">
								<label class="col-sm-2 control-label">分期：</label>
								<div class="col-sm-10">
									<input type="text" id="qishu" value="<{$vipData.staging_num}>/10" disabled class="form-control">
								</div>
							</div>
							<div class="clearfix"></div>
							<br/>
							<div class="form-group">
								<label class="col-sm-2 control-label">总消费股份：</label>
								<div class="col-sm-10">
									<input type="text" value="<{$vipData.stock_pirce}>元" disabled class="form-control">
								</div>
							</div>
							<div class="clearfix"></div>
							<br/>
							<div class="form-group">
								<label class="col-sm-2 control-label">授权码：</label>
								<div class="col-sm-10 pay-stoke-box">
									<if condition="$vipData.staging_num lt 10 && $stoke_status == 1">
	                       				<input type="text" class="form-control" name="key" id="key"/>
										<input value="每月打款" type="button" class="btn btn-primary pay-stoke-btn" onclick="payStokeMoneyView(<{$vipData.staging_num}>,<{$vipData.stock_pirce}>)" />
									<else />
										<p style="color:red;">该股东当月账务已结清！</p>
									</if>	
								</div>
							</div>
							<div class="clearfix"></div>
							<br/>
						</div>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
$(document).ready(function () {
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllStokeData?id=' + $("#id").val(),
        datatype: "json",
        height: 320,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 15,
        rowList: [10, 15, 30, 50],
        colNames : [ 'ID', '收入/支出', '金额', '打款日期', '红包码', '备注' ], 
        colModel : [ {name : 'id',index : 'id'},
                     {name : 'detail_type',index : 'detail_type',sortable : false,formatter : function(cellvalue, options, rowObject){
                    	 if(cellvalue == 1) {
                    		 content = '支出';
                    	 }else if(cellvalue == 2) {
                    		 content = '收入';
                    	 }
                    	 return content;
                	 }},
                	 {name : 'detail_price',index : 'detail_price'},
                	 {name : 'create_time',index : 'create_time',formatter: 'date',formatoptions: {srcformat:'u',newformat:'Y-m-d H:i:s'}},
                     {name : 'offset_code',index : 'offset_code'},
                     {name : 'remaker',index : 'remaker'}
                   ],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc",
    });
 	// 设置按钮
    $("#table_list").jqGrid('navGrid', '#pager_list', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    });
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
    
});

//改
$("#detail").click(function() {
	var id = $("#table_list").jqGrid('getGridParam','selrow');
	if(id != null) {
		layerDialog("账户明细",'__URL__/detail?id='+id,"90%","250px",true);
	}else {
		layer.msg("您没有选取数据！");
	}
})

//重置密码
function resetPwd(id) {
	layer.confirm('密码将重置为 <font style="color:red;">000000</font></br>确定执行？', function(index){
    	var index = layer.load(2);
    	$.ajax({
			url:"__URL__/updateStatus",
			type:"post",
			data:{'user_id':id,'field':'password','islock':"670b14728ad9902aecba32e22fa4f6bd"},
			success:function(json){
				var data = eval("("+json+")");
				if(data.status == 1){
					layer.msg(data.info);
					$('#table_list').trigger("reloadGrid");
				}else{
					layer.msg(data.info);
				}
				layer.close(index);
			}
		})
	});
}
//锁定&解锁
function updateLock(id,islock) {
	layer.confirm('确定执行？', function(index){
    	var index = layer.load(2);
    	$.ajax({
			url:"__URL__/updateStatus",
			type:"post",
			data:{'user_id':id,'field':'islock','islock':islock},
			success:function(json){
				var data = eval("("+json+")");
				if(data.status == 1){
					layer.msg(data.info);
					$('#table_list').trigger("reloadGrid");
				}else{
					layer.msg(data.info);
				}
				layer.close(index);
			}
		})
	});
}

function payStokeMoneyView(num,price){
	if(num >= 10){
		alert("当前款项已经结清！无法继续操作");
	}
	if($("#key").val() == ""){
		layer.msg("请输入授权码！");
		return false;
	}
	var result = yesno(price);
	var user_id = <{$user_id}>;
	if(result == true){
		$.ajax({
			url:"__URL__/payStokeMoney",
			type:"post",
			data:{user_id:user_id,key:$("#key").val()},
			success:function(data){
				data = eval("("+data+")");
				if(data.status == 1){
					$("#qishu").val(data.data+"/10");
					layer.msg(data.info);
					window.location.reload();
				}else{
					layer.msg(data.info);
				}
			}
		})
	}
}

function yesno(price) {
	if(confirm("确定将本月应结款项总价："+parseInt(price/10) +"元打入用户账户?")){
	   return true;
	 }
}
</script>
</html>